const {
	Http,
	ip
} = require('./http')

// api 接口参数说明  url data(默认为{}) method(默认为GET)
class Api extends Http {
	// 根据url确定上传图片或者视频
	upload(url, filePath) {
		wx.showLoading({
			title: '正在上传'
		})
		return new Promise((reslove, reject) => {
			wx.uploadFile({
				url: ip + url,
				filePath: filePath,
				name: 'file',
				header: {
					'Authorization': wx.getStorageSync('token')
				},
				success(res) {
				
					try {
						reslove(JSON.parse(res.data))
					} catch (error) {
						console.log(error);
					}
				},
				fail(res) {
					reject(res.data)
				},
				complete(res) {
					wx.hideLoading()
				}
			})
		})
	}
	// 上传多张图片
	uploadImages(files) {
		let arr = []
		for (let i = 0; i < files.length; i++) {
			arr.push(this.uploadImage(files[i]))
		}
		return Promise.all(arr)
	}
	uploadImage(filePath) {
		return this.upload('/api/index/uploadImage', filePath)
	}
	uploadVideo(filePath) {
		return this.upload('/api/index/uploadVideo', filePath)
	}
	wxpay(data) {
		return new Promise((reslove, reject) => {
			wx.requestPayment({
				timeStamp: data.timestamp,
				nonceStr: data.noncestr,
				package: data.package,
				signType: 'MD5',
				paySign: data.paysign,
				success(res) {
					reslove(res)
				},
				fail(res) {
					reject(res)
				}
			})
		})
	}
	banner(data){
		return this.request('/api/index/banner', data, "POST")
	}
	register(data) {
		return this.request('/api/index/register', data, "POST")
	}
	login(data) {
		return this.request('/api/index/login', data, "POST")
	}

	vipDes(data) {
		return this.request('/api/index/detail', data, "POST")
	}
	onlyProundct(data) {
		return this.request('/api/indent/only', data, "POST")
	}
	userinfo(data) {
		return this.request('/api/user/information', data, "POST")
	}
	saveInfo(data) {
		return this.request('/api/user/saveInfo', data, "POST")
	}

	orderNum(data) {
		return this.request('/api/indent/orderNum', data, "POST")
	}
	orderLog(data) {
		return this.request('/api/index/orderLog', data, "POST")
	}
	article(data) {
		return this.request('/api/index/detail', data, "POST")
	}
	goods(data) {
		return this.request('/api/index/goods', data, "POST")
	}
	goodsDetail(data) {
		return this.request('/api/index/goodsDetail', data, "POST")
	}
	orderList(data) {
		return this.request('/api/indent/orderList', data, "POST")
	}
	// 提交订单
	submit(data) {
		return this.request('/api/indent/affirm', data, "POST")
	}
	address(data) {
		return this.request('/api/user/address', data, "POST")
	}
	addressEdit(data) {
		return this.request('/api/user/addressEdit', data, "POST")
	}
	buy(data) {
		return this.request('/api/indent/buy', data, "POST")
	}
	popularize(data) {
		return this.request('/api/user/popularize', data, "POST")
	}
	// 个人小程序二维码
	poster(data) {
		return this.request('/api/user/qr', data, "POST")
	}
	// 推广海报
	posterImage(data) {
		return this.request('/api/user/poster', data, "POST")
	}
	goodsClassify(data) {
		return this.request('/api/index/goodsClassify', data, "POST")
	}
	cartAdd(data) {
		return this.request('/api/indent/cartAdd', data, "POST")
	}
	cart(data) {
		return this.request('/api/indent/cart',data,'POST')
	}
	cartChange(data) {
		return this.request('/api/indent/cartChange',data,'POST')
	}
	// 删除购物车商品
	cartDel(data) {
		return this.request('/api/indent/cartDel',data,'POST')
	}
	cancelOrder(data) {
		return this.request('/api/indent/clearOrder',data,'POST')
	}
	signFor(data) {
		return this.request('/api/indent/signFor',data,'POST')
	}
	orderPay(data) {
		return this.request('/api/indent/pay',data,'POST')
	}
	orderDetail(data) {
		return this.request('/api/indent/orderDetail',data,'POST')
	}
	team(data) {
		return this.request('/api/user/team',data,'POST')
	}
	// 佣金记录
	commission(data) {
		return this.request('/api/Financial/commission',data,'POST')
	}
	// 提现记录
	withdrawLog(data) {
		return this.request('/api/Financial/withdrawLog',data,'POST')
	}
	withdraw(data) {
		return this.request('/api/Financial/withdraw',data,'POST')
	}
	// 物流状态
	logistics(data) {
		return this.request('/api/indent/logistics',data,'POST')
	}
	setting(data) {
		return this.request('/api/index/getConfig',data,'POST')
	}
	// 获取个人资金信息
	getFinancialInfo() {
		return this.request('/api/Financial/info',null,'POST')
	}

}

const api = new Api;

module.exports = api